package com.guoxin.concurrentprogramming.chapter2;

import java.util.concurrent.TimeUnit;

/**
 * @author guoxin
 * @date 2019/7/15
 */
public class InterruptSleepingThread {

    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            System.out.println("start thread ....");
            while (true) {
                try {
                    TimeUnit.SECONDS.sleep(60);
                } catch (InterruptedException e) {
                    System.out.println("cached the exception,programming out");
                    Thread.currentThread().interrupt();
                    break;
                }
            }
            System.out.println("end thread ....");
        });

        t.start();

        TimeUnit.SECONDS.sleep(1);
        System.out.println("interrupt thread t");
        t.interrupt();
    }
}
